package cmpe451.group7.dbserver.service;

import java.util.List;

import javax.persistence.NoResultException;
import javax.persistence.Query;

public class QWrap {

	private Query q;

	public QWrap(Query q) {
		this.q = q;
	}

	public QWrap par(String pname, Object v) {
		q.setParameter(pname, v);
		return this;
	}

	@SuppressWarnings("unchecked")
	public <T> T single(Class<T> clazz) {
		try {
			return (T) q.getSingleResult();
		} catch (NoResultException nre) {
			return null;
		}
	}

	@SuppressWarnings("unchecked")
	public <T> List<T> multi(Class<T> clazz) {
		return (List<T>) q.getResultList();
	}
}